#include "ConstTable.h"
#include <iostream>
#include <vector>

using namespace std;

typedef int INTEGER;
typedef int INDEX;
typedef string STRING;
typedef bool BOOLEAN;

	ConstTable::ConstTable(){
		_size = 0;
	}
	INDEX ConstTable::insertCon(int constant){
		int i;
		int oldIndex = 0;
		BOOLEAN isInTable = false;
		for(i=0;i<_size;i++){
			if(_table.at(i)==constant){
				oldIndex = i;
				isInTable = true;
				break;
			}
		}
		if(isInTable == false){
			
			int newIndex = _size;
			_size +=1;
			_table.push_back(constant);
			return newIndex;
		}else{
			return oldIndex;
		}
	}
	INTEGER ConstTable::getSize(){
		return _size;
	}
	int ConstTable::getConstant(INDEX index){
		if(index >= _table.size()){
			return NULL;
		}
		return _table.at(index);
	}
	INDEX ConstTable::getConIndex(int constant){
		for(int i=0;i<_size;i++){
			if(_table.at(i) == constant){
				return i;
			}
		}
		return -1;
	}
	BOOLEAN ConstTable::hasCon(int constant){
		for(int i=0;i<_size;i++){
			if(_table.at(i)==constant){
				return true;
			}
		}
		return false;
	}






